package com.restaurant.application.root.commonui;

import com.nebutown.generation.BeanSpec;
import com.nebutown.generation.ClassName;

import static com.nebutown.generation.BeanSpec.listOf;
import static com.nebutown.generation.BeanSpec.mapOf;

public class CommonDataGen {

    private static final String DATA_PACKAGE_NAME = CommonDataGen.class.getPackage().getName() + ".data";
    private static final String DESTINATION = "src/main/java/";

    private static void generate(BeanSpec def) {
        def.generate(DESTINATION);
    }

    public static void main(String[] args) {
        new CommonDataGen()
                .nestedEditorDataGen()
                .rawTableDataGen();
    }

    private CommonDataGen nestedEditorDataGen() {

        generate(new BeanSpec(DATA_PACKAGE_NAME, "EditorPage")
                .add("name", String.class)
                .add("savePath", String.class)
                .add("cancelPath", String.class)
                .add("fields", listOf("EditorValue"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "ShowPage")
                .add("name", String.class)
                .add("editPath", String.class)
                .add("backPath", String.class)
                .add("acceptPath", String.class)
                .add("commitPath", String.class)
                .add("fields", listOf("ShowValue"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "EditorValue")
                .add("name", String.class)
                .addToGroup("value", "value", String.class)
                .addToGroup("source", "valueSelection", listOf("String"))
                .addToGroup("source", "button", String.class)
                .addToGroup("source", "dynamic", new ClassName("DynamicSearchField"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "DynamicSearchField")
                .add("path", String.class)
                .add("callName", String.class)
                .add("displayField", String.class)
                .add("reportField", String.class)
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "ShowValue")
                .add("name", String.class)
                .addToGroup("value", "value", String.class)
                .addToGroup("value", "list", new ClassName("EditorListValue"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "EditorElement")
                .add("insertBelowPath", String.class)
                .add("deletePath", String.class)
                .add("editPath", String.class)
                .add("seq", Long.class)
                .add("fields", listOf("ShowValue"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "EditorListValue")
                .add("name", String.class)
                .add("insertAtTopPath", String.class)
                .add("elements", listOf("EditorElement"))
        );

        return this;
    }

    private CommonDataGen rawTableDataGen() {

        generate(new BeanSpec(DATA_PACKAGE_NAME, "TableData")
                .add("tableName", String.class)
                .add("columns", listOf("ColumnData"))
                .add("rows", listOf("RowData"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "ColumnData")
                .add("columnId", String.class)
                .add("columnName", String.class)
                .add("sortedUp", Boolean.class)
                .add("sortUpPath", String.class)
                .add("sortDownPath", String.class)
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "RowData")
                .add("operations", mapOf("String"))
                .add("columns", mapOf("CellData"))
        );

        generate(new BeanSpec(DATA_PACKAGE_NAME, "CellData")
                .add("value", String.class)
                .add("clickPath", String.class)
                .add("doubleClickPath", String.class)
                .add("stateClass", String.class)
        );
        return this;
    }
}